<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script> //math.random（）取值范围  0<=result<1 的小数
//如果变换随机值得范围，可以乘以对应的值
    var result =Math.random();
    console.log(result);
    var arr =["hello","world","java","math"];
    var index = result*arr.length;
    index =parseInt(index);
    console.log(index);

    </script>
</html>